// D3DBtn1.cpp : Defines the entry point for the application.
//

#include "stdafx.h"
#include "D3DBtn1.h"


CComModule _Module;

#define MAX_LOADSTRING 100


struct PaintHandlers
{
	

} gPaintHandlers;






template <class T, COLORREF t_crBrushColor>
class CPaintBackground
{
public:
	
    CPaintBackground() { m_hbrBkgnd = CreateSolidBrush(t_crBrushColor); }
    ~CPaintBackground() { DeleteObject ( m_hbrBkgnd ); }
 
    BEGIN_MSG_MAP(CPaintBackground)
        MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBkgnd)
    END_MSG_MAP()
 
    LRESULT OnEraseBkgnd(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
    {
		T*   pT = static_cast<T*>(this);
		HDC  dc = (HDC) wParam;
		RECT rcClient;
 
        pT->GetClientRect ( &rcClient );
        FillRect ( dc, &rcClient, m_hbrBkgnd );
        return 1;    // we painted the background
    }
 
protected:
    HBRUSH m_hbrBkgnd;
};




typedef CWinTraits<WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, WS_EX_APPWINDOW> CMyWindowTraits;

template <class YourWindowType>
struct CPaintBackgroundGray: CPaintBackground<YourWindowType, RGB(200,200,200)>
{
};



class CMyWindow :    public CWindowImpl<CMyWindow, CWindow, CFrameWinTraits>
					,public CPaintBackgroundGray<CMyWindow>
{
public:
	

    DECLARE_WND_CLASS(_T("My Window Class"))
 
    BEGIN_MSG_MAP(CMyWindow)
		MESSAGE_HANDLER(WM_PAINT, OnPaint)
        MESSAGE_HANDLER(WM_CLOSE, OnClose)
        MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
        //COMMAND_ID_HANDLER(IDC_ABOUT, OnAbout)
		CHAIN_MSG_MAP(CPaintBackgroundGray<CMyWindow>)
    END_MSG_MAP()
 
    LRESULT OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
    {
        DestroyWindow();
        return 0;
    }
 
    LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
    {
        PostQuitMessage(0);
        return 0;
    }
 
    //LRESULT OnAbout(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
    //{
    //    MessageBox ( _T("Sample ATL window"), _T("About MyWindow") );
    //    return 0;
    //}

	LRESULT OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
	{

	}
};



int APIENTRY _tWinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPTSTR    lpCmdLine,
                     int       nCmdShow)
{
	_Module.Init(NULL, hInstance);
 
	CMyWindow wndMain;
	MSG msg;
 
    // Create & show our main window
	if( NULL == wndMain.Create ( NULL, CWindow::rcDefault, _T("My First ATL Window") ))
	{
		// Bad news, window creation failed
		return 1;
	}
 
	wndMain.ShowWindow(nCmdShow);
	wndMain.UpdateWindow();
 
    // Run the message loop
    while ( GetMessage(&msg, NULL, 0, 0) > 0 )
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }
 
    _Module.Term();
    return msg.wParam;
}











#ifdef MAKE__UNIT__TEST


void StartTesting()
{
	ptree pt;
	read_info( string("BackGroundTest1.info"), pt );
	string name = pt.get<string>("widgets.BackGround.Name");
	assert(name == string("BackGround1") );
	int L, T, W, H;    L= T= W= H= -1;
	L = pt.get<int>("widgets.BackGround.L");
	T = pt.get<int>("widgets.BackGround.T");
	W = pt.get<int>("widgets.BackGround.W");
	H = pt.get<int>("widgets.BackGround.H");
	assert(L==10);
	assert(T==10);
	assert(W=100);
	assert(H=50);
}

#endif